<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button @click="closeDrawer(1)">取 消</el-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">确 定</multiuse-button>
    </div>
  </div>
</template>
<script>
import { getWarehouseList, stockIn } from '@/api/dealerSale/SalesReturn/ReturnVehicle';

export default {
  data() {
    this.saveData = null;
    return {
      formList: this.createdFrom()
    };
  },
  props: ['list'],
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      let res = await getWarehouseList();
      this.formList.find(x => x.fieldName == 'returnWarehouse').itemList = res.data.list.map(x => ({ text: x.warehouseName, value: x.warehouseId }));
    },
    changeHandle(val) {
      this.saveData = val;
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        this.$refs.from.SUBMIT_FORM();
        console.log(this.saveData, 'this.saveData');
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          let arr = [];
          this.list.map(x => {
            arr.push(x.returnId);
          });
          json.operateType = 45231005;
          json.applyStatus = 45231005;
          json.ids = arr;
          let res = await stockIn(json);
          if (res.resultCode == 200) {
            this.$notify.success({
              title: '提示信息',
              message: '操作成功!'
            });
            this.$emit('close', json);
          } else {
            this.saveData = null;
          }
        }
      }
    },
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'returnWarehouse',
          placeholder: '请选择',
          itemList: [],
          selfCols: 1.5,
          rules: [{ required: true, message: '请选择', trigger: 'change' }]
        }
      ];
    }
  }
};
</script>
